<template>
	<view class="list">
		<!-- 头部 -->
		<view class="list_head flex-row-around">
			<view v-for="(item,index) in headlist" :key="index" class="head_bos" @click="Onhead(item)">
				<text :class="code == item.code?'head_a':'head_b'">{{item.title}}</text>
				<view v-if="code == item.code"></view>
			</view>
		</view>
		<!-- 数据 -->
		<view>
			<LoadMore ref="LoadMore" id="LoadMore" :diffHeight="124" :initData="initData" @dataRefresh='dataRefresh'>
				<text></text>
				<view v-for="(item,index) in List" :key="index" class="list_list"
					@click="Onpages(item.pay_status==2&&item.status=='normal'?'/pagesA/check/pay/pay?code='+item.order_code:'/pagesA/check/detail/detail?code='+item.order_code)">
					<view class="list_one flex-row-between">
						<view class="font14 font-323232 font-b">订单号:{{item.order_code}}</view>
						<text class="font13 font-969696">{{item.typename}}</text>
					</view>
					<view class="list_info flex-row-between">
						<image class="list_image" mode="aspectFill" src="@/static/yy.jpg"></image>
						<view class="list_bos flex-column-between">
							<view class="font14 font-323232 ellipsis">{{item.physical_name}}</view>
							<view class="font14 font-323232">体检人:{{item.physical_user_name}}</view>
							<view class="ellipsis font13 font-969696">体检时间:{{item.time}}
								{{item.begin_time}}~{{item.end_time}}
							</view>
						</view>
					</view>
					<view class="list_two flex-row-between">
						<view class="font14 font-969696">{{item.createtime}}</view>
						<view class="font14">
							<text class="font-323232">订单金额:</text>
							<text class="font-6bcbb6 font-b">￥{{item.money}}</text>
						</view>
					</view>
					<view class="list_btn flex-row-start font12">
						<view class="btn_b" v-if="item.status=='normal'" @click.stop="Oncolse(item)">取消订单</view>
						<view class="btn_a" v-if="item.pay_status==2&&item.status=='normal'"
							@click.stop="Onpages('/pagesA/check/pay/pay?code='+item.order_code)">立即支付</view>
					</view>
				</view>
			</LoadMore>
		</view>
	</view>
</template>

<script>
	import LoadMore from "@/components/loadMore.vue";
	export default {
		components: {
			LoadMore
		},
		data() {
			return {
				//传参数据
				initData: {
					url: 'physicalOrderList', //接口
					//data里得传参
					param: {
						pay_status: '2',
						status: 'normal'
					},
				},
				List: [],
				code: 'normal1',
				//头部列表
				headlist: [{
						title: '待支付',
						id: 1,
						code: 'normal1',
					},
					{
						title: '待体检',
						id: 2,
						code: 'normal2'
					},
					// {
					// 	title: '已体检',
					// 	id: 3,
					// 	code: 'patient'
					// },
					{
						title: '已取消',
						id: 4,
						code: 'cancel',
					},
					{
						title: '已退款',
						id: 5,
						code: 'refund',
					}
				],
			}
		},
		methods: {
			//切换
			Onhead(res) {
				if (res.id == 1) {
					this.initData.param.pay_status = 2
					this.initData.param.status = 'normal'
				}
				if (res.id == 2) {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'normal'
				}
				if (res.id == 4) {
					this.initData.param.pay_status = 2
					this.initData.param.status = 'cancel'
				}
				if (res.id == 5) {
					this.initData.param.pay_status = 1
					this.initData.param.status = 'refund'
				}
				this.code = res.code
				this.List = []
				this.$refs.LoadMore.oncutRefresh(this.initData)
			},
			//返回数据
			dataRefresh(e) {
				e.forEach(item => {
					item.createtime = this.$base.formatTime(new Date(item.createtime *
						1000), "yyyy/MM/dd hh:mm:ss")
					if (item.pay_status == 2) {
						if (item.status == 'normal') {
							item.typename = '待支付'
						}
						if (item.status == 'cancel') {
							item.typename = '已取消'
						}
					}
					if (item.pay_status == 1) {
						if (item.status == 'refund') {
							item.typename = '已退款'
						}
						if (item.status == 'normal') {
							item.typename = '预约成功'
						}
					}
				})
				this.List = e
			},
			//页面跳转
			Onpages(e) {
				uni.navigateTo({
					url: e,
				})
			},
			//取消订单
			Oncolse(e) {
				var that = this
				let url = ''
				if (e.pay_status == 2) {
					url = 'cancelPhysicalOrder'
				}
				if (e.pay_status == 1) {
					url = 'refundPhysicalOrder'
				}
				uni.showModal({
					title: '取消体检提示',
					content: '取消后您将失去本号源,是否确认取消',
					confirmText: '保留号源', //确定文字
					confirmColor: '#6bcbb6',
					cancelText: '确定取消', //取消文字
					cancelColor: '#9c9c9c',
					success(res) {
						if (res.confirm) {} else if (res.cancel) {
							that.$Http({
								url: url,
								type: 'POST',
								show: true,
								data: {
									order_code: e.order_code,
								}
							}).then(res => {
								if (res.code == 1) {
									that.$refs.LoadMore.oncutRefresh(that.initData)
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
	@import url("list.less");
</style>
